
#include <kogi/item.h>

#include <attest/attest.h>

ATTEST(item, char)
{
    for (int i = -256; i != 256; ++i)
    {
        char const c = (char)i;
        struct kogi_item item = kogi_from_char(c);
#ifdef KOGI_ENABLE_ITEM_TYPE_SAFETY
        ATTEST_EQ(KOGI_ITEM_CHAR, item.type);
#endif
        ATTEST_EQ(c, kogi_to_char(item));
    }
}

ATTEST(item, cstring)
{
    char const* cstr = "Hello, World!";
    struct kogi_item item = kogi_from_cstr(cstr);
#ifndef KOGI_ENABLE_ITEM_TYPE_SAFETY
    ATTEST_EQ(KOGI_ITEM_CSTRING, item.type);
#endif
    ATTEST_EQ(cstr, kogi_to_cstr(item));
}

ATTEST(item, double)
{
    for (double d = -10.5; d < 10; d += 1)
    {
        struct kogi_item item = kogi_from_double(d);
#ifndef KOGI_ENABLE_ITEM_TYPE_SAFETY
        ATTEST_EQ(KOGI_ITEM_DOUBLE, item.type);
#endif
        ATTEST_EQ(d, kogi_to_double(item));
    }
}

ATTEST(item, float)
{
    for (float f = -10.5; f < 10; f += 1)
    {
        struct kogi_item item = kogi_from_float(f);
#ifndef KOGI_ENABLE_ITEM_TYPE_SAFETY
        ATTEST_EQ(KOGI_ITEM_FLOAT, item.type);
#endif
        ATTEST_EQ(f, kogi_to_float(item));
    }
}

ATTEST(item, int)
{
    for (int i = -256; i != 256; ++i)
    {
        struct kogi_item item = kogi_from_int(i);
#ifdef KOGI_ENABLE_ITEM_TYPE_SAFETY
        ATTEST_EQ(KOGI_ITEM_INT, item.type);
#endif
        ATTEST_EQ(i, kogi_to_int(item));
    }
}

ATTEST(item, int8)
{
    for (int i = -256; i != 256; ++i)
    {
        int8_t const i8 = (int8_t)i;
        struct kogi_item item = kogi_from_int8(i8);
#ifdef KOGI_ENABLE_ITEM_TYPE_SAFETY
        ATTEST_EQ(KOGI_ITEM_INT8, item.type);
#endif
        ATTEST_EQ(i8, kogi_to_int8(item));
    }
}

ATTEST(item, int16)
{
    for (int i = -256; i != 256; ++i)
    {
        int16_t const i16 = (int16_t)i;
        struct kogi_item item = kogi_from_int16(i16);
#ifdef KOGI_ENABLE_ITEM_TYPE_SAFETY
        ATTEST_EQ(KOGI_ITEM_INT16, item.type);
#endif
        ATTEST_EQ(i16, kogi_to_int16(item));
    }
}


